/**
 * @date 10:08:19 AM
 * EducationGroupController.java
 * Administrator
 * TODO
 */
package com.qs.education.controller;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qs.education.bean.entity.EducationGroup;
import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.api.ResponseListBean;
import com.qs.education.bean.beans.EducationGroupResponse;
import com.qs.education.service.IGroupAPPService;
/**
 * @class EducationGroupController	
 * @author Warren
 * @description
 * @date Nov 8, 2018 
 */
@RestController
public class EducationGroupController {
	
	@Autowired
	private IGroupAPPService iGroupAPPService;
	private final Logger log = Logger.getLogger(this.getClass());
					
	/**
	 * @author Warren
	 * @param id 群号
	 * @return Map<String,Object>
	 * @description id为群号(1000001开始增长)，根据群号搜索班群
	 * @date Nov 9, 2018
	 */
	@RequestMapping("/group/searchById")
	public Map<String, Object> searchById(Long id) {
		log.info("api");
		EducationGroupResponse educationGroupResponse = iGroupAPPService.searchById(id);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("educationGroupResponse", educationGroupResponse);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param userId 申请的用户id
	 * @param groupId 申请的班群号
	 * @param sendType 申请类型,教师或学生
	 * @return ResponseBean
	 * @description 申请加入班群
	 * @date Nov 19, 2018
	 */
	@RequestMapping("/group/apply")
	public ResponseBean apply(Long userId,Long groupId,int sendType){
		log.info("api");
		ResponseBean responseBean = iGroupAPPService.apply(userId, groupId, sendType);
		return responseBean;
	}
	
	/**
	 * @author Warren
	 * @param id 申请班群消息id
	 * @param messageStatus 教师处理结果
	 * @return ResponseBean
	 * @description 教师处理班群申请
	 * @date Nov 13, 2018
	 */
	@RequestMapping("/group/applyHandle")
	public ResponseBean applyHandle(Long id,int messageStatus){
		ResponseBean responseBean = iGroupAPPService.applyHandle(id, messageStatus);
		return responseBean;
	}
	
	/**
	 * @author Warren
	 * @param studentId 学生id
	 * @return ResponseListBean<EducationGroup>
	 * @description 根据学生id获取学生的班群列表
	 * @date Nov 13, 2018
	 */
	@RequestMapping("/group/findGroupByStudentId")
	public Map<String, Object> findGroupByStudentId(Long studentId){
		ResponseListBean<EducationGroup> responseListBean = iGroupAPPService.findGroupByStudentId(studentId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseListBean", responseListBean);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param ids 移除学生的id集合
	 * @return ResponseBean
	 * @description 批量移除学生
	 * @date Nov 13, 2018
	 */
	@RequestMapping("/group/removeStudents")
	public Map<String, Object> removeStudents(String[] ids,String groupId){
		ResponseBean responseBean = iGroupAPPService.removeStudents(ids,groupId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseBean", responseBean);
		return map;
	}
	
	/**
	 * @Description 根据教师ID 查询教师的所有群组
	 * @author Leon
	 * @date   Nov 9, 2018
	 * @param  
	 * @return Map<String,Object>
	 */
	@RequestMapping("/group/findGroupByTeacherId")
	public Map<String ,Object> findGroupByTeacherId(String teacherId){
		log.info("app controller findGroupByTeacherId");
		ResponseListBean<EducationGroupResponse> response = new ResponseListBean<EducationGroupResponse>();
		response = iGroupAPPService.findGroupByTeacherId(teacherId);
		Map<String,Object> map = new HashMap<String,Object>();

		map.put("educationGroupResponse", response);
		return map;
	}
	
	/**
	 * @Description 根据年级 和 班级 创建多个班群
	 * @author Leon
	 * @date   Nov 12, 2018
	 * @param  
	 * @return Map<String,Object>
	 */
	@RequestMapping("/group/createGroups")
	public Map<String,Object> createGroups(@RequestBody String params){
		log.info("app controller CreateGroup");
		EducationGroupResponse response = new EducationGroupResponse();
		response = iGroupAPPService.createGroups(params);
		Map<String,Object> map = new HashMap<String,Object>();

		map.put("educationGroupResponse", response);
		return map;
	}
	

	/**
	 * @Description 根据教师ID 移除教师
	 * @author Leon
	 * @date   Nov 13, 2018
	 * @param  teacherId 教师ID  groupID 群组ID
	 * @return Map<String,Object>
	 */
	@RequestMapping("/group/removeTeacher")
	public Map<String,Object> removeTeacher(String teacherId,String groupId){
		log.info("app controller removeTeacher");
		EducationGroupResponse response = new EducationGroupResponse();
		response = iGroupAPPService.removeTeacher(teacherId,groupId);
		Map<String,Object> map = new HashMap<String,Object>();

		map.put("educationGroupResponse", response);
		return map;
	}
	
	/**
	 * @Description 转让班群
	 * @author Leon
	 * @date   Nov 13, 2018
	 * @param  teacherId 教师ID  groupID 群组ID
	 * @return Map<String,Object>
	 */
	@RequestMapping("/group/transferGroup")
	public Map<String,Object> transferGroup(String teacherId,String groupId){
		log.info("app controller transferGroup");
		EducationGroupResponse response = new EducationGroupResponse();
		response = iGroupAPPService.transferGroup(teacherId, groupId);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("educationGroupResponse", response);
		return map;
	}
	
	/**
	 * @Description 修改班群
	 * @author Leon
	 * @date   Nov 14, 2018
	 * @param  
	 * @return Map<String,Object>
	 */
	@RequestMapping("/group/modifyGroup")
	public Map<String,Object> modifyGroup(EducationGroup group){
		System.out.println("=========="+group.toString());
		System.out.println("============================");
		EducationGroupResponse response = new EducationGroupResponse();
		Map<String,Object> map = new HashMap<String,Object>();
		response = iGroupAPPService.modifyGroup(group);
		map.put("educationGroupResponse", response);
		return map;
	}
	
	/**
	 * @Description 删除群组
	 * @author Leon
	 * @date   Nov 14, 2018
	 * @param  
	 * @return Map<String,Object>
	 */
	@RequestMapping("/group/deleteGroup")
	public Map<String,Object> deleteGroupById(String groupId){
		log.info("app group controller");
		EducationGroupResponse response = new EducationGroupResponse();
		response = iGroupAPPService.deleteGroupById(groupId);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("educationGroupResponse", response);
		return map;
	}
}
